from command import Command
from abc import abstractmethod

__all__ = [
    "Light", "LightOnCommand", "LightOffCommand",
    "DimmerLightOnCommand", "DimmerLightOffCommand"
]

class Light:
    def __init__(self, location: str):
        self._location = location
        self._level = 0

    def on(self):
        self._level = 100
        print("Light is on")

    def off(self):
        self._level = 0
        print("Light is off")

    def dim(self, level: int):
        self._level = level
        if level == 0:
            print("Light is off")
        else:
            print(f"Light is dimmed to {self._level}%")

    @property
    def level(self):
        return self._level


class LightCommand(Command):
    def __init__(self, light: Light):
        self._light = light
        self._state_history = []

    @abstractmethod
    def execute(self):
        ...

    def undo(self):
        if self._state_history:
            self._light.dim(self._state_history.pop())


class LightOnCommand(LightCommand):
    def execute(self):
        self._state_history.append(self._light.level)
        self._light.on()


class LightOffCommand(LightCommand):
    def execute(self):
        self._state_history.append(self._light.level)
        self._light.off()


class DimmerLightOnCommand(LightCommand):
    def execute(self):
        self._state_history.append(self._light.level)
        self._light.dim(75)


class DimmerLightOffCommand(LightCommand):
    def execute(self):
        self._state_history.append(self._light.level)
        self._light.off()